﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Xml.Serialization;
using System.Threading;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
    public class ScoreCommand : Command, ICommandInfo
    {
        public override string HelpText { get { return "Shows your score and other character-related information"; } }

        [NonSerialized, XmlIgnore]
        public static List<string> Words = new List<string>() { "SCORE", "SC" };

        public override List<string> FirstWords { get { return Words; } }

        public static string ToReplace =
            "Score for {Name}" + Environment.NewLine +
            "Abilities: {Abilities:Abilities}{AbilityName} - {EnablesCommands}{\n}{Abilities:Abilities}" + Environment.NewLine +
            "Strength: {Strength}" + Environment.NewLine;

        [MethodVisible]
        public static List<PerceivedEventAndAudience> PerformMethod(CommandToPerform cmd, IGameThing source, IGameThing target, PropertyData args, PropertyData modifyingArguments)
        {
            TextReplacement ReplacementInstructions = new TextReplacement()
            {
                Replacements = new List<IdentifierAndValue>()
                {
                    new IdentifierAndValue("{Name}", "Prop:Name"),
                    new IdentifierAndValue("{Strength}", "Prop:PropertyData:Strength"),
                    new IdentifierAndValue("{Abilities:Abilities}", new TextReplacement()
                    {
                        Replacements = new List<IdentifierAndValue>()
                        {
                            new IdentifierAndValue("{AbilityName}", "Prop:1:AbilityName"),
                            new IdentifierAndValue("{EnablesCommands}", "Prop:1:EnableCommandsList")
                        }
                    })
                }
            };

            List<PerceivedEventAndAudience> events = new List<PerceivedEventAndAudience>();
            GameThingBaseClass sourceChar = source as GameThingBaseClass;
            string allParams = (cmd.UserInput == null) ? string.Empty : cmd.UserInput;

            string text = ReplacementInstructions.PerformReplacement(ToReplace, sourceChar);
            EventToPerceive evt = CreateObservable(source, text);
            events.Add(new PerceivedEventAndAudience() { Event = evt, Audience = new AssociatedIDCollection(sourceChar.AssociatedID) });

            return events;
        }

        [MethodVisible]
        public static EventToPerceive CreateObservable(IAssociatedID source, string text)
        {
            return new GeneralEventToPerceive()
            {
                ShowToSource = new Event(text, ViewType.Sense),
                Sources = new AssociatedIDCollection(source.AssociatedID)
            };
        }

    }
}
